/*
 * PisoInferior.h
 *
 *  Created on: 22/04/2013
 *      Author: juan
 */

#include "PisoInferior.h"

using namespace std;

PisoInferior::PisoInferior(GLuint program, GLuint segments) :
		Figure(program) {
	piso = new Floor(program);
	cilindros = new std::list<Cilinder*>();

	for (int i = 0; i <= 6; i++) {
		cilindros->push_front(new Cilinder(program, segments));
	}
}

PisoInferior::~PisoInferior() {
	for (std::list<Cilinder*>::iterator it = cilindros->begin(); it != cilindros->end(); it++) {
		delete (*it);
	}
	delete (piso);
}

void PisoInferior::draw(GLuint program, glm::mat4 & world_matrix) {
	glm::mat4 matriz = world_matrix * this->model_matrix;
	//this -> piso -> translate(glm::vec3(0.0f,0.0f,-1.0f));
	this->piso->draw(program,matriz);
	glm::mat4 m = glm::mat4(1.0f);
	glm::mat4 matriz_cilindros = glm::mat4(1.0f);
	matriz_cilindros = glm::translate(matriz, glm::vec3(0.0f, 0.0f, 1.5f)); //Ubico el cilindro sobre el suelo.
	matriz_cilindros = glm::scale(matriz_cilindros, glm::vec3(0.45f, 0.45f, 3.0f)); //Hago mas alto el cilindro.

	std::list<Cilinder*>::iterator it = cilindros->begin();
	m = glm::translate(matriz_cilindros, glm::vec3(-10.5f, -4.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
	m = glm::translate(matriz_cilindros, glm::vec3(-10.5f, 4.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
	m = glm::translate(matriz_cilindros, glm::vec3(16.0f, 4.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
	m = glm::translate(matriz_cilindros, glm::vec3(5.0f, -2.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
	m = glm::translate(matriz_cilindros, glm::vec3(5.0f, 4.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
	m = glm::translate(matriz_cilindros, glm::vec3(16.0f, -2.8f, 0.0f));
	(*it)->draw(program,m);
	it++;
}

void PisoInferior::set_textures(unsigned int id_floor_texture, unsigned int id_columns_texture) {
	piso->set_texture_id(id_floor_texture);

	for (list<Cilinder*>::iterator it = this->cilindros->begin(); it != this->cilindros->end(); it++) {
		(*it)->set_texture_id(id_columns_texture);
	}
}
